C#########################################################
C This file is part of OpenAD released under the LGPL.   #
C The full COPYRIGHT notice can be found in the top      #
C level directory of the OpenAD distribution             #
C#########################################################
C
C$OPENAD XXX File_start [head.f]
      SUBROUTINE head(X, Y)
          use OAD_tape
          use OAD_rev

C original arguments get inserted before version
C         ! and declared here together with all local variables
C         ! generated by xaifBooster

      use OAD_active
      use w2f__types
      use oad_intrinsics
      use oad_intrinsics
      use oad_intrinsics
      IMPLICIT NONE
C
C     **** Global Variables & Derived Type Definitions ****
C
      INTEGER(w2f__i8) OpenAD_Symbol_0
      INTEGER(w2f__i8) OpenAD_Symbol_1
      INTEGER(w2f__i8) OpenAD_Symbol_2
      INTEGER(w2f__i8) OpenAD_Symbol_3
      INTEGER(w2f__i8) OpenAD_Symbol_4
      INTEGER(w2f__i8) OpenAD_Symbol_5
      INTEGER(w2f__i8) OpenAD_Symbol_6
      INTEGER(w2f__i8) OpenAD_Symbol_7
C
C     **** Parameters and Result ****
C
      type(active) :: X(1:1)
      type(active) :: Y(1:1)
C
C     **** Local Variables and Functions ****
C
      INTEGER(w2f__i4) I
      INTEGER(w2f__i4) select_expr_temp_0
      REAL(w2f__8) OpenAD_Symbol_8
      REAL(w2f__8) OpenAD_Symbol_9
      REAL(w2f__8) OpenAD_lin_0
      REAL(w2f__8) OpenAD_lin_1
      type(active) :: OpenAD_prp_0
      type(active) :: OpenAD_prp_1


          integer iaddr
          external iaddr
C
C     **** Top Level Pragmas ****
C
C$OPENAD INDEPENDENT(X)
C$OPENAD DEPENDENT(Y)
C
C     **** Statements ****
C

         if (our_rev_mode%plain) then
C original function
C$OPENAD XXX Template ad_template.f
      I = 1
      Y(1)%v = 2.0
      select_expr_temp_0 = I
      IF (select_expr_temp_0.EQ.1) go to 4
      IF (select_expr_temp_0.EQ.2) go to 8
      GO TO 9
 9    CONTINUE
      Y(1)%v = X(1)%v
      GO TO 6
 4    CONTINUE
      Y(1)%v = X(1)%v
      GO TO 6
 8    CONTINUE
      Y(1)%v = X(1)%v
      GO TO 6
 6    CONTINUE
      Y(1)%v = (Y(1)%v*Y(1)%v)
          end if
          if (our_rev_mode%tape) then
C taping
C$OPENAD XXX Template ad_template.f
      I = 1
      Y(1)%v = 2.0
      select_expr_temp_0 = I
      IF (select_expr_temp_0.EQ.1) go to 40
      IF (select_expr_temp_0.EQ.2) go to 44
      GO TO 45
 45   CONTINUE
      Y(1)%v = X(1)%v
      OpenAD_Symbol_3 = 3_w2f__i8
      integer_tape(integer_tape_pointer) = OpenAD_Symbol_3
      integer_tape_pointer = integer_tape_pointer+1
      GO TO 49
 40   CONTINUE
      Y(1)%v = X(1)%v
      OpenAD_Symbol_1 = 1_w2f__i8
      integer_tape(integer_tape_pointer) = OpenAD_Symbol_1
      integer_tape_pointer = integer_tape_pointer+1
      GO TO 49
 44   CONTINUE
      Y(1)%v = X(1)%v
      OpenAD_Symbol_2 = 2_w2f__i8
      integer_tape(integer_tape_pointer) = OpenAD_Symbol_2
      integer_tape_pointer = integer_tape_pointer+1
      GO TO 49
 49   CONTINUE
      OpenAD_lin_0 = Y(1)%v
      OpenAD_lin_1 = Y(1)%v
      Y(1)%v = (Y(1)%v*Y(1)%v)
      double_tape(double_tape_pointer) = OpenAD_lin_0
      double_tape_pointer = double_tape_pointer+1
      double_tape(double_tape_pointer) = OpenAD_lin_1
      double_tape_pointer = double_tape_pointer+1
          end if
          if (our_rev_mode%adjoint) then
C adjoint
      double_tape_pointer = double_tape_pointer-1
      OpenAD_Symbol_8 = double_tape(double_tape_pointer)
      double_tape_pointer = double_tape_pointer-1
      OpenAD_Symbol_9 = double_tape(double_tape_pointer)
      OpenAD_prp_1%d = OpenAD_prp_1%d+Y(1)%d*(OpenAD_Symbol_8)
      OpenAD_prp_0%d = OpenAD_prp_0%d+Y(1)%d*(OpenAD_Symbol_9)
      Y(1)%d = 0.0d0
      Y(1)%d = Y(1)%d+OpenAD_prp_1%d
      OpenAD_prp_1%d = 0.0d0
      Y(1)%d = Y(1)%d+OpenAD_prp_0%d
      OpenAD_prp_0%d = 0.0d0
      integer_tape_pointer = integer_tape_pointer-1
      OpenAD_Symbol_0 = integer_tape(integer_tape_pointer)
      IF (OpenAD_Symbol_0.EQ.1) go to 94
      IF (OpenAD_Symbol_0.EQ.2) go to 93
      IF (OpenAD_Symbol_0.EQ.3) go to 92
 94   CONTINUE
      X(1)%d = X(1)%d+Y(1)%d
      Y(1)%d = 0.0d0
      GO TO 96
 93   CONTINUE
      X(1)%d = X(1)%d+Y(1)%d
      Y(1)%d = 0.0d0
      GO TO 96
 92   CONTINUE
      X(1)%d = X(1)%d+Y(1)%d
      Y(1)%d = 0.0d0
      GO TO 96
 96   CONTINUE
      Y(1)%d = 0.0d0
          end if
        end subroutine head
